//
// Created by v on 24-11-26.
//

#ifndef JKLIBS_CMUISHOWWITHLVGL_H
#define JKLIBS_CMUISHOWWITHLVGL_H

#include "CMUIShowInterface.h"

#include "lvgl/lv_version.h"
#include "lvgl/lv_conf.h"
#include "lvgl/lvgl.h"
#include "lvgl/src/lv_init.h"

#include "cm_utils.h"

class CMUIShowWithLVGL : public CMUIShowInterface
{
  public:
    CMUIShowWithLVGL();
    virtual ~CMUIShowWithLVGL();

    virtual int showMain() override;

    virtual int runLoop() override;
    virtual int runOnce() override;

    int uiShowImage(const char *image_file) override;
    int uiShowImage(const char *buf, unsigned long long buf_size, int width, int height) override;
    int uiShowImage(const char            *image_buf,
                    unsigned long long int image_buf_size) override;
    int uiShowText(const char *text) override;
    int init() override;
    int deinit() override;
    int ctl(int type, void *args) override;

  protected:
    int ui_init();
    int ui_deinit();

    int labelTextInit();

  private:
    int run() override;

    lv_obj_t * labelMain;
    lv_obj_t * labelText;
    lv_obj_t * labelImage;
    unsigned long long timeShowLast;
    void *image_buffer;
    unsigned long long image_buffer_size;
};

#endif // JKLIBS_CMUISHOWWITHLVGL_H
